<template>
  <div>
    <j-modal
    :title="title"
    :width="width"
    :confirmLoading="confirmLoading"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item
          label="盘点开始时间"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="startTime">
          <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.startTime" />
        </a-form-model-item>
        <a-form-model-item
          prop="endTime"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="盘点结束时间">
          <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.endTime" />
        </a-form-model-item>
        <a-form-model-item 
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="选择盘点公司" 
              prop="company">
              <!-- <j-search-select-tag placeholder="请输入" v-model="model.company" :dictOptions="company_code" mode="multiple">
              </j-search-select-tag> -->
              <j-search-select-tag
                  placeholder="请选择"
                  v-model="model.company"
                  dict="company_code"
                  mode="multiple">
              </j-search-select-tag>
            </a-form-model-item>
            
      </a-form-model>
    </j-modal>
  </div>
</template>

<script>
  import moment from "moment"
  import { httpAction } from '@/api/manage'
  export default {
    name: 'AssetStartModal',
    components: {
    },
    props: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        disableSubmit:false,
        searchOptions:[{
            text:"全部",
            value:"1"
          },{
            text:"在职",
            value:"2"
          },{
            text:"离职",
            value:"3"
        }],
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        confirmLoading: false,
        
        url: {
          add: "/assets/assetsPreliminaryResults/startAssets",
          edit: "/test/ceshiNote/edit",
          queryById: "/test/ceshiNote/queryById"
        }
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
      validatorRules(){
        return{
            startTime: [{ required: true, message: '请选择开始时间!' }],
            endTime: [{ required: true, message: '请选择结束时间!' }],
            company: [{ required: true, message: '请选择盘点公司!' }],
        }
      }
    },
    created() {
     //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      moment,
      // 新增
      add () {
        // this.visible=true
        this.edit({});
        // this.$nextTick(()=>{
        //   this.$refs.realForm.add();
        // })
        this.edit(this.modelDefault);
      },
      // 编辑、详情
      edit(record) {
        console.log('333')
        console.log(record)
        this.model = Object.assign({}, record);
        this.visible=true
        
        // this.$nextTick(()=>{
        //   this.$refs.realForm.edit(record);
        // })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      handleOk () {
        const that = this;
        console.log('2222')
        console.log(this.model)
        // 触发表单验证
         this.$refs.form.validate(valid => {
          console.log('333')
          console.log(valid)
          if (valid) {
            that.confirmLoading = true;
            httpAction(this.url.add,this.model,'post').then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      }
    }
  }
</script>
<style scoped>
  .toolBt{
    display: flex;
    align-content: center;
  }
</style>